package vrp;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.util.Date;
import java.util.LinkedList;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import vrp.Customer;
import vrp.SOrderItem;

@PersistenceCapable
public class SOrder {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private Key customer;

    @Persistent
    private Date date;

    @Persistent
    private int recurringType;

    @Persistent
    private Date startDate;

    @Persistent
    private Date endDate;

    @Persistent(mappedBy = "sorder")
    @Element(dependent = "true")
    @Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="deliveryDate asc"))
    private LinkedList<SOrderItem> sorderItems;

    @Persistent
    private int sorderStatus;

    public SOrder(Key customer, int recurringType, Date startDate, Date endDate) {
    	this.customer = customer;
    	this.date = new Date();
    	this.recurringType = recurringType;
    	this.startDate = startDate;
    	this.endDate = endDate;
    	this.sorderItems = new LinkedList<SOrderItem>();
    	this.sorderStatus = 0; //not processed
    }

    public Key getKey() {
        return this.key;
    }

    public Key getCustomer() {
        return this.customer;
    }

    public Date getDate() {
        return this.date;
    }

    public int getRecurringType() {
        return this.recurringType;
    }

    public Date getStartDate() {
        return this.startDate;
    }
    
    public Date getEndDate() {
        return this.endDate;
    }
    
    public int getSOrderStatus() {
        return this.sorderStatus;
    }

    public LinkedList<SOrderItem> getSOrderItems() {
        return this.sorderItems;
    }

    public void setKey(Key someKey) {
    	this.key = someKey;
    }

    public void setCustomer(Key customer) {
        this.customer = customer;
    }

    public void setDate(Date date) {
        this.date= date;
    }

    public void setRecurringType(int recurringType) {
        this.recurringType = recurringType;
    }
    
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }    
    
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }    

    public void setSOrderStatus(int sorderStatus) {
        this.sorderStatus = sorderStatus;
    }

    public void setSOrderItems(LinkedList<SOrderItem> sorderItems) {
        this.sorderItems = sorderItems;
    }
    
    public void addSOrderItem(SOrderItem sorderItem) {
        this.sorderItems.add(sorderItem);
    }
}